package com.itheima.mapper;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @param
 * @return
 */
public interface UserMapper {
    @Select("SELECT  * FROM user")//注解，值是SQL语句
    @Results(id = "otm" ,value = {//这里因为只有一个值，所以可以简化
            @Result(id = true,column = "id",property = "id"),//id=true表示这是主键列，column表示查询的列名，property表示与之对应的实体类中的成员变量名
            @Result(column = "username",property = "username"),
            @Result(column = "sex",property = "sex"),
            @Result(property = "ordersList" ,javaType = List.class ,column = "id",//注意，对多的属性是property不是column，对应的是该变量的类型的.class，而不是泛型，这里是一个List集合，所以是 List.class
                    many=@Many(select = "com.itheima.mapper.OrdersMapper.findById",fetchType = FetchType.LAZY))
    })//many=@Many多对多标志注解，select = "com.itheima.mapper.OrdersMapper.findById",表示命名空间加id的方式找到唯一的statement对象，执行操作
    //fetchType = FetchType.LAZY表示懒加载
    List<User> findAll();
}
